package com.example.demo.demos.example;

import com.example.demo.demos.pojo.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author lyh
 * @date 2025/4/15 14:26
 */
public class StringSum {
    public static void main(String[] args) {
        User user1 = new User("张三", "25.6", null);
        User user2 = new User("李四", "5.3", null);
        List<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);

        double sum = users.stream()
                .map(User::getAge)
                .filter(Objects::nonNull)
                .mapToDouble(Double::parseDouble)
                .sum();
        int avg = (int) (sum / users.size());
        System.out.println("sum = " + sum);
        System.out.println("sum = " + avg);

    }
}
